<?php
/*
Plugin Name: BeamPulse

*/

if (!defined('WP_CONTENT_URL'))
      define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
if (!defined('WP_CONTENT_DIR'))
      define('WP_CONTENT_DIR', ABSPATH.'wp-content');
if (!defined('WP_PLUGIN_URL'))
      define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins');
if (!defined('WP_PLUGIN_DIR'))
      define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');

function activate_beampulse() {
  add_option('web_property_id', 'UA-0000000-0');
}

function deactive_beampulse() {
  delete_option('web_property_id');
}

function admin_init_beampulse() {
  register_setting('BeamPulse', 'web_property_id');
}

function admin_menu_beampulse() {
  add_options_page('BeamPulse', 'BeamPulse', 'manage_options', 'beampulse', 'options_page_beampulse');
}

function options_page_beampulse() {
  include(WP_PLUGIN_DIR.'/beampulse/options.php');  
}

function beampulse() {
  $web_property_id = get_option('web_property_id');
?>
<script type="text/javascript">
 (function()
 { var s = document.createElement('script');
 s.type = 'text/javascript'; 
 s.async = true;
 s.src = ('https:' == document.location.protocol ? 'https://' : 'http://' )+'s3.amazonaws.com/js-project/'+'<?php echo $web_property_id1 ?>';  
 var x = document.getElementsByTagName('script')[0];
 x.parentNode.insertBefore(s, x);
 })();
</script>
<?php
}

register_activation_hook(__FILE__, 'activate_beampulse');
register_deactivation_hook(__FILE__, 'deactive_beampulse');

if (is_admin()) {
  add_action('admin_init', 'admin_init_beampulse');
  add_action('admin_menu', 'admin_menu_beampulse');
}

if (!is_admin()) {
  add_action('wp_head', 'beampulse');
}

?>
